package com.linq.cool.file.service.impl;

import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.linq.cool.file.service.FileService;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: yqlin
 * @Date: 2021/1/1 21:00
 * @Description:
 * @Version: 1.0.0
 */
@Service
public class FastDfsSysFileServiceImpl implements FileService {
    @Value("${fdfs.domain}")
    private String domain;
    @Autowired
    private FastFileStorageClient fastFileStorageClient;

    @Override
    public String uploadFile(MultipartFile file) throws Exception {
        return domain + fastFileStorageClient
                .uploadFile(file.getInputStream(), file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()), null)
                .getFullPath();
    }
}
